// 配置路由
import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)

const router = new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      redirect: '/login',
      hidden: true,
      component: () => import('@/page/login/Login.vue')
    },
    {
      path: '/login',
      name: 'Login',
      hidden: true,
      component: () => import('@/page/login/Login.vue')
    },
    {
      path: '/register',
      name: 'Register',
      hidden: true,
      component: () => import('@/page/login/Register.vue')
    },

    // 学生主页路由
    {
      path: '/student/home',
      name: '学生主页',
      roles: ['student'],
      iconClass: 'fa fa-user-circle',
      component: () => import('@/page/student/Home.vue'),
      children: [
        {
          path: '/student/home/info',
          name: '个人信息页',
          roles: ['student'],
          iconClass: 'fa fa-id-card',
          component: () => import('@/page/student/StudentHome/StudentInfo.vue')
        },
        {
          path: '/student/home/Collect',
          name: '数据采集',
          roles: ['student'],
          iconClass: 'fa fa-database',
          component: () => import('@/page/student/StudentHome/DataCollect.vue')
        }
      ]
    },

    // 心理健康模块路由
    {
      path: '/student/mental',
      name: '心理健康监测',
      iconClass: 'fa fa-heartbeat',
      roles: ['student'],
      component: () => import('@/page/student/Home.vue'),
      children: [
        {
          path: '/student/mental/warning',
          name: '风险预警',
          iconClass: 'fa fa-exclamation-triangle',
          roles: ['student'],
          component: () => import('@/page/student/mental/RiskWarning.vue')
        },
        {
          path: '/student/mental/trend',
          name: '趋势分析',
          iconClass: 'fa fa-line-chart',
          roles: ['student'],
          component: () => import('@/page/student/mental/TrendAnalysis.vue')
        },
        {
  path: '/message',
  name: '留言板',
  roles: ['student'], // 允许学生和家长访问
  iconClass: 'fa fa-comments',
  component: () => import('@/components/common/MessageBoard.vue')
},
      ]
    },




    // 家长菜单页
    {
      path: '/parent',
      name: '家长中心',
      roles: ['parent'],
      component: () => import('@/components/common/Layout.vue'),
      children: [
        {
          path: '/parent/RiskDisplay',
          name: '风险感知',
          iconClass: 'fa fa-exclamation-triangle',
          component: () => import('@/page/parent/RiskDisplay.vue')
        },
       
        {
          path: '/parent/StudentInfoTag',
          name: '学生基础身份标识',
          iconClass: 'fa fa-user',
          component: () => import('@/page/parent/StudentInfoTag.vue')
        },
   // 合并留言板路由
   {
  path: '/message',
  name: '留言板',
  roles: ['parent'], // 允许学生和家长访问
  iconClass: 'fa fa-comments',
  component: () => import('@/components/common/MessageBoard.vue')
    },

      ],
   
    },



    // 管理员模块
        {
          path: '/admin',
          name: '管理员首页',
          component: () => import('@/components/common/Layout.vue'),
          roles: ['admin'],
          iconClass: 'fa fa-tachometer',
          children: [
            {
              path: '/admin/DataSysConfig',
              name: '数据管理与系统配置',
              roles: ['admin'],
              iconClass: 'fa fa-database', 
              component: () => import('@/page/admin/DataSysConfig.vue')
            },
            {
              path: '/admin/RiskStatAlert',
              name: '风险与预警',
              iconClass: 'fa fa-exclamation-triangle',
              roles: ['admin'],
              component: () => import('@/page/admin/RiskStatAlert.vue')
            },
            {
              path: '/admin/UserManage',
              name: '用户管理',
              iconClass: 'fa fa-cogs',
              roles: ['admin'],
              component: () => import('@/page/admin/UserManage.vue')
            }
          ]
        }
  ]
})

// // 全局前置守卫
// router.beforeEach((to, from, next) => {
//   const userInfo = JSON.parse(localStorage.getItem('userInfo') || '{}')
//   if (!userInfo.token && to.path !== '/login') {
//     next('/login')
//     return
//   }
//   next()
// })

export default router